package com.alibaba.weex.module;

import android.util.Log;

import com.nat.sensor_accelerometer.HLAccelerometerModule;
import com.nat.sensor_accelerometer.HLModuleResultListener;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.bridge.JSCallback;
import com.taobao.weex.common.WXModule;

import java.util.HashMap;

/**
 * 加速传感器
 *
 * @version 1.0
 * @since 2017/7/3
 */
public class SensorAccelerometerModule extends WXModule {

    @JSMethod
    public void get(final JSCallback jsCallback) {
        HLAccelerometerModule.getInstance(mWXSDKInstance.getContext()).get(new HLModuleResultListener() {
            @Override
            public void onResult(Object o) {
                Log.d("-----事件>>>", "get--->>" + o.toString());
                jsCallback.invoke(o);
            }
        });
    }

    @JSMethod
    public void watch(HashMap<String, Integer> param, final JSCallback jsCallback) {
        HLAccelerometerModule.getInstance(mWXSDKInstance.getContext()).watch(param, new HLModuleResultListener() {
            @Override
            public void onResult(Object o) {
                Log.d("-----事件>>>", "watch--->>" + o.toString());
                jsCallback.invokeAndKeepAlive(o);
            }
        });
    }

    @JSMethod
    public void clearWatch(final JSCallback jsCallback) {
        HLAccelerometerModule.getInstance(mWXSDKInstance.getContext()).clearWatch(new HLModuleResultListener() {
            @Override
            public void onResult(Object o) {
                jsCallback.invoke(o);
            }
        });
    }
}